// @algorithm @lc id=309 lang=cpp 
// @title best-time-to-buy-and-sell-stock-with-cooldown


// @test([1,2,3,0,2])=3
// @test([1])=0
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        vector<int> f = {-prices[0], 0, 0};// 持有，冷冻期，非冷冻期
        for(int i=1; i<prices.size(); i++){
            f = { max(f[0], f[2]-prices[i]),
                f[0] + prices[i],
                max(f[1], f[2]),
            };
        }
        return max(f[1], f[2]);
    }
};